<template>
	<view class="login">
		<uni-nav-bar height="80rpx" :statusBar='true' title="登录"></uni-nav-bar>
		<view>
			<u-button text="登录" type="primary" @click="login"></u-button>
			<u-button text="检查session" type="primary" @click="check"></u-button>
			<button open-type="chooseAvatar" @chooseavatar="avatar">完善信息</button>
			<image :src="headsrc"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				headsrc:"",
			};
		},
		methods: {
			login() {
				uni.login({
					provider: 'weixin',
					success: (result) => {
						console.log(result);
						let code = result.code;
						uni.$u.http.get(`/api/wx/wx-login?code=${code}`).then(response => {
							console.log(response);
							let openId = response.data[0].openid;
						})
						uni.getUserInfo({
							provider:"weixin",
							withCredentials:true,
							success(response) {
								console.log(response);
							},
							fail(err){
								console.log(err);
							}
						})
					}
				});
			},
			check(){
				uni.checkSession({
					success(result) {
						console.log(result);
					},
					fail(err) {
						console.log(err);
					}
				});
			},
			avatar(res){
				console.log("头像数据",res);
				this.headsrc = res.detail.avatarUrl
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login {}
</style>
